package com.zhuang.collection.exercise;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

public class CollectionExercise {
	public static void main(String[] args) {
		List<Dog> list = new ArrayList<>();
		list.add(new Dog("小黑", 3));
		list.add(new Dog("大黄", 100));
		list.add(new Dog("大壮", 8));
		System.out.println("增强for遍历");
		for (Object item : list) {
			System.out.println(item);
		}
		System.out.println("lambda遍历");
		list.forEach(System.out::println);
		System.out.println("迭代器遍历");
		Iterator<Dog> iterator = list.iterator();
		while (iterator.hasNext()) {
			System.out.println(iterator.next());
		}

	}

	static class Dog {
		private String name;
		private int age;

		public Dog(String name, int age) {
			this.name = name;
			this.age = age;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public int getAge() {
			return age;
		}

		public void setAge(int age) {
			this.age = age;
		}

		@Override
		public String toString() {
			return "Dog{" + "name='" + name + '\'' + ", age=" + age + '}';
		}
	}
}
